//
//  BDShopInfoDeatilViewController.m
//  BadBoy
//
//  Created by wen on 2017/3/16.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "BDShopInfoDeatilViewController.h"
#import "BDUserModel.h"
#import "BDShopReservationViewController.h"
#import "BDSubtitleTableViewCell.h"
#import "BDTaocanTableViewCell.h"
#import "BDDetailInfoTableViewCell.h"
#import "BDCommondTableViewCell.h"
#import "BDEmptyTableViewCell.h"
#import "BDShopDetailModel.h"
#import <AMap2DMap-NO-IDFA/MAMapKit/MAMapKit.h>
#import "BDShopHeaderView.h"
#import "BDShopCommentViewController.h"
#import "BDShopEditCommondViewController.h"
#import "BDShopCommonModel.h"
#import "CallExternalProcessBehavior.h"
#import "UIViewController+BackButtonHandler.h"
#import "BDShopReceiveHongbaoView.h"
#import "BDRedEnvelopeModel.h"
#import "BDDiscoverShopJSLIstViewController.h"

@interface BDShopInfoDeatilViewController ()<UITableViewDataSource,UITableViewDelegate, BackButtonHandlerProtocol>
{
    BOOL needAllbutton;
    BOOL isFirst;
}
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *datasource;
@property (nonatomic, strong) NSMutableArray *sectionStyleArray;
@property (nonatomic, strong) BDShopDetailModel *detailModel;
@property (nonatomic, strong) UIView *tanleHeaderView;
@property (nonatomic, strong) UIButton *rightButton;
@property (nonatomic, strong) YYAnimatedImageView *hongbaoView;

@end

@implementation BDShopInfoDeatilViewController

/*
 1.在获取DataSource的时候进行判断，最后得出最终 DataSource
 2.在这个过程中要保存每个section中的headertitle、cellClass、identifier
 3.为了计算高度方便，需要一个basecell
 */

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self layoutViews];
    [self bindRAC];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    if (isFirst == NO) {
        [self.datasource removeAllObjects];
        self.startPage = @"1";
        [self requestData];
        isFirst = YES;
    }else if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"needRefreshShopInfo"] boolValue] == YES) {
        [self.datasource removeAllObjects];
        self.startPage = @"1";
        [self requestData];
        [[NSUserDefaults standardUserDefaults] setObject:@NO forKey:@"needRefreshShopInfo"];
    }
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    NSString *url = [NSString stringWithFormat:@"%@shop/%@/view", KBDBaseURL, @(self.detailModel.shop_id)];
    NSString *headValid = [BDUserModel getHeaderValidation];
    RACSignal *signal = [[BDNetworkingServer yy_PUT:url parameters:nil validation:headValid automaticProcessingError:YES] execute:nil];
    [signal subscribeNext:^(id  _Nullable x) {
        
    }];
    
    [signal subscribeError:^(NSError * _Nullable error) {
        
    }];
}

- (BOOL)navigationShouldPopOnBackButton{
    if (self.favBlock && self.detailModel.is_fav == NO) {
        self.favBlock();
    }
    return YES;
}

- (void)layoutViews{
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:self.rightButton];
    self.navigationItem.rightBarButtonItems = @[rightItem];
}

- (void)bindRAC{
    [[self.rightButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        [BDUserModel judgeCurrentUserWithNormalBlock:^{
            NSString *shoucangTitle = self.detailModel.is_fav == YES ? ASLocalizedString(@"取消关注"): ASLocalizedString(@"关注");
            NSString *url = [NSString stringWithFormat:@"%@shop/%@/fav", KBDBaseURL, @(self.detailModel.shop_id)];
            NSString *headValid = [BDUserModel getHeaderValidation];
            [MBManager showLoadingAlert:ASLocalizedString(@"请稍后")clickHidden:NO clickBlock:nil];
            RACSignal *signal = [[BDNetworkingServer yy_POST:url parameters:nil validation:headValid automaticProcessingError:YES] execute:nil];
            [signal subscribeNext:^(id  _Nullable x) {
//                [MBManager hideAlert];
                [MBManager showBriefAlert:[NSString stringWithFormat:ASLocalizedString(@"%@成功"), shoucangTitle] clickHidden:NO clickBlock:nil];
                self.detailModel.is_fav = [x[@"status"] boolValue];
                self.rightButton.selected = self.detailModel.is_fav;
            }];
            
            [signal subscribeError:^(NSError * _Nullable error) {
//                [MBManager hideAlert];
                [MBManager showBriefAlert:[NSString stringWithFormat:ASLocalizedString(@"%@失败"), shoucangTitle] clickHidden:NO clickBlock:nil];
                // BDLog(ASLocalizedString(@"收藏失败：%@"), error);
            }];
        }];
    }];
}

- (void)requestData{
    [MBManager showLoadingAlert:ASLocalizedString(@"加载中")clickHidden:NO clickBlock:nil];
    NSString *headerVale = [BDUserModel getHeaderValidation];
    NSString *url = [KBDBaseURL stringByAppendingString:[NSString stringWithFormat:@"shop/%@", self.shopID]];
    
    RACSignal *signal = [[BDNetworkingServer yy_GET:url parameters:nil validation:headerVale automaticProcessingError:NO] execute:nil];
    [signal subscribeNext:^(id  _Nullable x) {
        self.detailModel = [BDShopDetailModel mj_objectWithKeyValues:x];
//        self.detailModel.distance = self.distances;
        self.rightButton.selected = self.detailModel.is_fav;
        //第一个section
        NSMutableArray *array  = @[@{@"image":@"dianhua_2", @"title":self.detailModel.phone, @"subTitle":ASLocalizedString(@"联系商家"),@"needRight":@"1"},
                                   @{@"image":@"youhui", @"title":ASLocalizedString(@"人均价格"), @"subTitle":[NSString stringWithFormat:ASLocalizedString(@"¥  %ld元"), self.detailModel.consumption]}].mutableCopy;
        if (self.detailModel.girls) {
            [array addObject:
             @{@"image":@"discoverDetail_JS", @"title":ASLocalizedString(@"技师"), @"subTitle":[NSString stringWithFormat:ASLocalizedString(@"%zd名"), self.detailModel.girls]}];
        }
        
        [self.datasource addObject:array];
        [self.sectionStyleArray addObject:@{@"cellClass":[BDSubtitleTableViewCell class], @"identifier":@"subCell", @"sectionTitle":@""}];
        
        //第二个section,经理部分
//        if (self.detailModel.type != BDShopTypekTV && self.detailModel.type != BDShopTypeMuzu && self.detailModel.type != BDShopTypeOther) {
            if (self.detailModel.managers.count != 0) {
                [self.datasource addObject:self.detailModel.managers];
                [self.sectionStyleArray addObject:@{@"cellClass":[BDTaocanTableViewCell class], @"identifier":@"taocanCell", @"sectionTitle":ASLocalizedString(@"更多优惠请与经理预订")}];
            }
//        }
        
        //第三个section
        if (self.detailModel.content != nil && ![self.detailModel.content isEqualToString:@""]) {
            [self.datasource addObject:@[self.detailModel.content]];
            [self.sectionStyleArray addObject:@{@"cellClass":[BDDetailInfoTableViewCell class], @"identifier":@"detailCell", @"sectionTitle":ASLocalizedString(@"商家详情")}];
        }
        
        [self requestCommon];
    }];
    
    [signal subscribeError:^(NSError * _Nullable error) {
//        [MBManager hideAlert];
        [self showErrorViewWithTapBlock:^{
            [MBManager showLoadingAlert:ASLocalizedString(@"加载中")clickHidden:NO clickBlock:nil];
            [self requestData];
        }];
    }];
}

- (void)requestCommon{
    //请求评论
    NSString *headerVale = [BDUserModel getHeaderValidation];
    NSString *url = [KBDBaseURL stringByAppendingString:[NSString stringWithFormat:@"shop/%@/comments?page=%@&size=%@", self.shopID, self.startPage, self.pageSize]];
    
    RACSignal *signal = [[BDNetworkingServer yy_GET:url parameters:nil validation:headerVale automaticProcessingError:NO] execute:nil];
    [signal subscribeNext:^(id  _Nullable x) {
        self.isEnd = [x[@"is_end"] boolValue];
        if (self.isEnd == YES) {
            self.tableView.mj_footer = nil;
        }else{
            self.startPage = x[@"next_page"];
        }
        
        //第四个section
        NSArray *commArr = x[@"list"];
        if (commArr.count == 0) {
            [self.datasource addObject:@[@""]];
            needAllbutton = NO;
            [self.sectionStyleArray addObject:@{@"cellClass":[BDEmptyTableViewCell class], @"identifier":@"emptyCell", @"sectionTitle":ASLocalizedString(@"网友评论(0)")}];
        }else{
            [self.datasource addObject:[BDShopCommonModel mj_objectArrayWithKeyValuesArray:x[@"list"]]];
            needAllbutton = YES;
            [self.sectionStyleArray addObject:@{@"cellClass":[BDCommondTableViewCell class], @"identifier":@"commondCell", @"sectionTitle":[NSString stringWithFormat:ASLocalizedString(@"网友评论(%zd)"), self.detailModel.comment]}];
        }
        [self.tableView.mj_header endRefreshing];
        self.tableView.mj_header = nil;
        [self.tableView.mj_footer endRefreshing];
        self.tableView.hidden = NO;
        if (self.tableView.tableHeaderView == nil) {
            self.tableView.tableHeaderView = self.tanleHeaderView;
        }
        [self.tableView reloadData];
        [self reloadTbaleHeader];
        [MBManager hideAlert];
        if (self.detailModel.hongbao) {
            self.hongbaoView.hidden = NO;
            [self.view bringSubviewToFront:self.hongbaoView];
        }else{
            self.hongbaoView.hidden = YES;
        }
    }];
    
    [signal subscribeError:^(NSError * _Nullable error) {
//        [MBManager hideAlert];
        [self showErrorViewWithTapBlock:^{
            [MBManager showLoadingAlert:ASLocalizedString(@"加载中")clickHidden:NO clickBlock:nil];
            [self requestCommon];
        }];
    }];
}

- (void)reloadTbaleHeader{
    if (self.detailModel) {
        for (UIView *subView in self.tanleHeaderView.subviews.firstObject.subviews) {
            if ([subView isKindOfClass:[MAMapView class]]) {
                MAMapView *mapView = (MAMapView *)subView;
                
                MAPointAnnotation *a1 = [[MAPointAnnotation alloc] init];
                a1.coordinate = CLLocationCoordinate2DMake(self.detailModel.latitude, self.detailModel.longitude);
                a1.title = self.detailModel.title;
                a1.subtitle = ASLocalizedString(@"暂时没数据");
                [mapView addAnnotations:@[a1]];
                [mapView showAnnotations:@[a1] animated:YES];
                
            }else {
                for (UIView *litSubView in subView.subviews) {
                    if ([litSubView isKindOfClass:[UILabel class]]) {
                        UILabel *label = (UILabel *)litSubView;
                        label.text = self.detailModel.address;
                        label.height = [label.text heightWithFont:label.font width:label.width];
                        label.centerY = subView.height / 2.0;
                    }
                }
            }
        }
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.datasource.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == self.datasource.count - 1) {
        return [self.datasource.lastObject count] > 3 ? 3 : [self.datasource.lastObject count];
    }
    return [self.datasource[section] count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    Class curClas = [self.sectionStyleArray[indexPath.section] objectForKey:@"cellClass"];
    return [curClas getCellHeightWithModel:self.datasource[indexPath.section][indexPath.row]];

}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return [BDShopHeaderView getHeightWithModel:self.detailModel];
    }
    return 35;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        BDShopHeaderView *secHead = (BDShopHeaderView *)[tableView dequeueReusableHeaderFooterViewWithIdentifier:@"shopHead"];
        if (secHead == nil) {
            secHead = [[BDShopHeaderView alloc] initWithFrame:CGRectMake(0, 0, kBDScreenWidth, [BDShopHeaderView getHeightWithModel:self.detailModel]) imageArray:self.detailModel.images];
        }
        if (self.detailModel) {
            [secHead configeWithModel:self.detailModel];
        }
        return secHead;
    }else{
        UIView *secHead = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"titleHead"];
        if (secHead ==nil) {
            secHead = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kBDScreenWidth, 35)];
            secHead.backgroundColor = [UIColor whiteColor];
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 6, kBDScreenWidth, 13)];
            label.textColor = KBDColorBlue;
            label.font= [UIFont systemFontOfSize:14];
            [secHead addSubview:label];
        }
        NSString *title = [self.sectionStyleArray[section] objectForKey:@"sectionTitle"];;
        for (UIView *subView in secHead.subviews) {
            if ([subView isKindOfClass:[UILabel class]]) {
                UILabel *label = (UILabel *)subView;
                label.text = title;
                label.centerY = label.superview.height / 2.0;
            }
        }
        return secHead;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == self.datasource.count - 1 && needAllbutton == YES) {
        return 45;
    }else {
        return 10;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section == self.datasource.count - 1 && needAllbutton == YES) {
        UIView *footerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"commFooter"];
        if (footerView == nil) {
            footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kBDScreenWidth, 45)];
            footerView.backgroundColor = [UIColor clearColor];
            
            UIButton *allButton = [UIButton buttonWithType:UIButtonTypeCustom];
            allButton.frame = CGRectMake(0, 0, kBDScreenWidth, 35);
            [allButton setTitle:ASLocalizedString(@"查看全部 >")forState:UIControlStateNormal];
            allButton.backgroundColor = [UIColor whiteColor];
            allButton.titleLabel.font = [UIFont systemFontOfSize:14];
            [allButton setTitleColor:KBDColorBlue forState:UIControlStateNormal];
            [[allButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
                BDShopCommentViewController *commentVC = [[BDShopCommentViewController alloc] init];
                commentVC.datasource = self.datasource.lastObject;
                commentVC.isEnd = self.isEnd;
                commentVC.pageSize = self.pageSize;
                commentVC.startPage = self.startPage;
                commentVC.detailModel = self.detailModel;
                [self.navigationController pushViewController:commentVC animated:YES];
            }];
            [footerView addSubview:allButton];
        }
        return footerView;
    }else {
        UIView *footerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"normalFooter"];
        if (footerView == nil) {
            footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kBDScreenWidth, 10)];
            footerView.backgroundColor = [UIColor clearColor];
        }
        return footerView;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *identifier = [self.sectionStyleArray[indexPath.section] objectForKey:@"identifier"];
    Class curClas = [self.sectionStyleArray[indexPath.section] objectForKey:@"cellClass"];
    
    BDBaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[curClas alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    if ([cell isKindOfClass:[BDTaocanTableViewCell class]]) {
        BDTaocanTableViewCell *taocanCell = (BDTaocanTableViewCell *)cell;
        id ob = self.detailModel.managers.count > indexPath.row ? self.detailModel.managers[indexPath.row] : nil;
        [taocanCell configeWithManager:ob shenqingStatus:self.detailModel.manager_status buttonClick:^{
            
        }];
    }else{
        [cell configeWithModel:self.datasource[indexPath.section][indexPath.row]];
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if ([cell isKindOfClass:[BDSubtitleTableViewCell class]]) {
        if (indexPath.row == 0) {
            [CallExternalProcessBehavior phoneWithPhoneNumber:self.detailModel.phone callFinished:^{
                NSDictionary *dict = @{MerchantType_callShop:self.detailModel.title};
                [MobClick event:MerchantName_callShop attributes:dict];
            }];
        }else if (indexPath.row == 2) {
            BDDiscoverShopJSLIstViewController *jsVC = [[BDDiscoverShopJSLIstViewController alloc] init];
            jsVC.shop_id = [NSString stringWithFormat:@"%zd", self.detailModel.shop_id];
            [self.navigationController pushViewController:jsVC animated:YES];
        }
    }
    else if ([cell isKindOfClass:[BDTaocanTableViewCell class]]) {
        // BDLog(ASLocalizedString(@"点击了经理部分"));
        if (self.detailModel.managers.count >= 1) {
            //下个版本再这样做
            BDShopManagerModel *manager = self.detailModel.managers[indexPath.row];
            BDShopReservationViewController *reservationVC = [[BDShopReservationViewController alloc] init];
            reservationVC.manager = manager;
            reservationVC.shopTitle = self.detailModel.title;
            [self.navigationController pushViewController:reservationVC animated:YES];
        }
    }else if ([cell isKindOfClass:[BDCommondTableViewCell class]]) {
        // BDLog(ASLocalizedString(@"点击了评论部分"));
    }
}

- (UIButton *)rightButton{
    if (!_rightButton) {
        self.rightButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30 ,30)];
        [_rightButton setImage:[UIImage imageNamed:@"shop_guanzhu"] forState:UIControlStateNormal];
        [_rightButton setImage:[UIImage imageNamed:@"shop_guanzhu_sel"] forState:UIControlStateSelected];
    }
    return _rightButton;
}

- (UITableView *)tableView{
    if (!_tableView) {
        self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, kBDTopHeight, kBDScreenWidth, kBDScreenHeight - kBDTopHeight) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.sectionFooterHeight = 10;
        _tableView.hidden = YES;
        _tableView.bounces = NO;
        _tableView.separatorInset = UIEdgeInsetsZero;
        [self.view addSubview:self.tableView];
    }
    return _tableView;
}

- (UIView *)tanleHeaderView{
    if (!_tanleHeaderView) {
        self.tanleHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kBDScreenWidth, 150 * kBDScreenWidth / 375 + 50)];
        _tanleHeaderView.backgroundColor = kBDColorGray;
        
        UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kBDScreenWidth, 150 * kBDScreenWidth / 375 + 40)];
        [_tanleHeaderView addSubview:headView];
        
        headView.backgroundColor = [UIColor whiteColor];
        MAMapView *mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, kBDScreenWidth, 150 * kBDScreenWidth / 375)];
        mapView.scrollEnabled = NO;
        [headView addSubview:mapView];
        mapView.zoomLevel = 14.25;
        UIView *locationView = [[UIView alloc] initWithFrame:CGRectMake(0, mapView.bottom, kBDScreenWidth, 40)];
        [headView addSubview:locationView];
        UIImageView *locationImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 20, 20)];
        locationImage.image = [UIImage imageNamed:@"dizhi_3"];
        locationImage.centerY = locationView.height / 2.0;
        [locationView addSubview:locationImage];
        
        UILabel *locaLabel = [[UILabel alloc] initWithFrame:CGRectMake(locationImage.right + 10, 0, kBDScreenWidth - locationImage.right - 10 - 25, 40)];
        locaLabel.font = [UIFont systemFontOfSize:14];
        locaLabel.numberOfLines = 0;
        locaLabel.textColor = [UIColor colorWithHexString:@"#6d6d6d"];
        [locationView addSubview:locaLabel];
        
        UIImageView *pushImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
        pushImage.image = [UIImage imageNamed:@"righ"];
        pushImage.right = kBDScreenWidth - 10;
        pushImage.centerY = 20;
        [locationView addSubview:pushImage];
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = locationView.bounds;
        [[button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            [CallExternalProcessBehavior routeNavigationWithLongitue:self.detailModel.longitude latitue:self.detailModel.latitude];
        }];
        [locationView addSubview:button];
    }
    return _tanleHeaderView;
}

- (NSMutableArray *)datasource{
    if (!_datasource) {
        self.datasource = [NSMutableArray array];
    }
    return _datasource;
}

- (NSMutableArray *)sectionStyleArray{
    if (!_sectionStyleArray) {
        self.sectionStyleArray = [NSMutableArray array];
    }
    return _sectionStyleArray;
}

- (YYAnimatedImageView *)hongbaoView{
    if (!_hongbaoView) {
        static YYImage *image2 =  nil;
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            image2 = [YYImage imageNamed:@"hongbao_gif2.gif"];
        });
        
        self.hongbaoView = [[YYAnimatedImageView alloc] initWithImage:image2];
        _hongbaoView.size = CGSizeMake(82, 82);
        _hongbaoView.right = kBDScreenWidth - 10;
        _hongbaoView.bottom = kBDScreenHeight - 30;
        _hongbaoView.userInteractionEnabled = YES;
        [self.view addSubview:_hongbaoView];
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = _hongbaoView.bounds;
        [_hongbaoView addSubview:button];
        [[button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            [MBManager showLoadingAlert:@"" clickHidden:NO clickBlock:nil];
            NSString *url = [NSString stringWithFormat:@"%@shops/%@/HB", KBDBaseURL, @(self.detailModel.shop_id)];
            NSString *headValid = [BDUserModel getHeaderValidation];
            NSDictionary *para = @{@"id":@(self.detailModel.shop_id)};
            RACSignal *signal = [[BDNetworkingServer yy_POST:url parameters:para validation:headValid automaticProcessingError:YES] execute:nil];
            [signal subscribeNext:^(id  _Nullable x) {
                [MBManager hideAlert];
                NSArray *redEnvelopes = [BDRedEnvelopeModel mj_objectArrayWithKeyValuesArray:x];
                [BDShopReceiveHongbaoView showWithDatasource:redEnvelopes];
            }];
            [signal subscribeError:^(NSError * _Nullable error) {
//                [MBManager hideAlert];
                [MBManager showBriefAlert:ASLocalizedString(@"网络错误")clickHidden:YES clickBlock:nil];
            }];
            
        }];
    }
    return _hongbaoView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
